// pages/student/student.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: "student",
    classNumber: 1701,
    className: "自然辩证法",
    border: true,
    classes: []
  },
  onLoad: function(opts) {
    console.log(app.globalData.userinfo)
  },
  onChange(event) {
    console.log(event.detail)
    this.setData({
      active: event.detail,
    });

    let that = this
    wx.navigateTo({
      url: "/pages/" + that.data.active + "/" + that.data.active
    })
  },
  onSignin(event) {
    let classNumber = event.currentTarget.dataset.no
    console.log(classNumber)
    let url = "/pages/signin/signin?" + "classNumber=" + classNumber
    wx.navigateTo({
      url: url
    })
  },
  onShow: function (opts) {
    let that = this
    console.log("调用getClass")
    wx.cloud.callFunction({
      name: "getClass",
      data: {
        _id: app.globalData.userInfo._id
      },
      success: res => {
        console.log("云函数调用成功:", res)
        that.setData({
          classes: res.result.data.classes
        })

      },
      fail: res => {
        console.log("云函数调用失败")
      }
    })
  }
})